package controllers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.OwnerDomainModel;

import data.OwnerDomainData;

public class DeleteOwnerSiteServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		String domainName = (String) request.getParameter("domain");
		OwnerDomainData oData = new OwnerDomainData();
		OwnerDomainModel ownerDomain = oData.getByDomain(domainName);
		if (ownerDomain != null && request.getUserPrincipal().getName().equalsIgnoreCase(ownerDomain.getUsername())) {
			oData.delete(ownerDomain);
		}
		
		response.sendRedirect("/profile/view");
	}
}
